using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
namespace CXDB
{
	/// <summary>
	/// Strongly-typed collection for the CxRemark class.
	/// </summary>
    [Serializable]
	public partial class CxRemarkCollection : ActiveList<CxRemark, CxRemarkCollection>
	{	   
		public CxRemarkCollection() {}
        
        /// <summary>
		/// Filters an existing collection based on the set criteria. This is an in-memory filter
		/// Thanks to developingchris for this!
        /// </summary>
        /// <returns>CxRemarkCollection</returns>
		public CxRemarkCollection Filter()
        {
            for (int i = this.Count - 1; i > -1; i--)
            {
                CxRemark o = this[i];
                foreach (SubSonic.Where w in this.wheres)
                {
                    bool remove = false;
                    System.Reflection.PropertyInfo pi = o.GetType().GetProperty(w.ColumnName);
                    if (pi.CanRead)
                    {
                        object val = pi.GetValue(o, null);
                        switch (w.Comparison)
                        {
                            case SubSonic.Comparison.Equals:
                                if (!val.Equals(w.ParameterValue))
                                {
                                    remove = true;
                                }
                                break;
                        }
                    }
                    if (remove)
                    {
                        this.Remove(o);
                        break;
                    }
                }
            }
            return this;
        }
		
		
	}
	/// <summary>
	/// This is an ActiveRecord class which wraps the CX_Remark table.
	/// </summary>
	[Serializable]
	public partial class CxRemark : ActiveRecord<CxRemark>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public CxRemark()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}
		
		private void InitSetDefaults() { SetDefaults(); }
		
		public CxRemark(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}
        
		public CxRemark(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}
		 
		public CxRemark(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}
		
		protected static void SetSQLProps() { GetTableSchema(); }
		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}
		}
		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("CX_Remark", TableType.Table, DataService.GetInstance("CXDB"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarRID = new TableSchema.TableColumn(schema);
				colvarRID.ColumnName = "rID";
				colvarRID.DataType = DbType.Int32;
				colvarRID.MaxLength = 0;
				colvarRID.AutoIncrement = true;
				colvarRID.IsNullable = false;
				colvarRID.IsPrimaryKey = true;
				colvarRID.IsForeignKey = false;
				colvarRID.IsReadOnly = false;
				colvarRID.DefaultSetting = @"";
				colvarRID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarRID);
				
				TableSchema.TableColumn colvarGuid = new TableSchema.TableColumn(schema);
				colvarGuid.ColumnName = "Guid";
				colvarGuid.DataType = DbType.Guid;
				colvarGuid.MaxLength = 0;
				colvarGuid.AutoIncrement = false;
				colvarGuid.IsNullable = true;
				colvarGuid.IsPrimaryKey = false;
				colvarGuid.IsForeignKey = false;
				colvarGuid.IsReadOnly = false;
				colvarGuid.DefaultSetting = @"";
				colvarGuid.ForeignKeyTableName = "";
				schema.Columns.Add(colvarGuid);
				
				TableSchema.TableColumn colvarTypeID = new TableSchema.TableColumn(schema);
				colvarTypeID.ColumnName = "TypeID";
				colvarTypeID.DataType = DbType.Int32;
				colvarTypeID.MaxLength = 0;
				colvarTypeID.AutoIncrement = false;
				colvarTypeID.IsNullable = true;
				colvarTypeID.IsPrimaryKey = false;
				colvarTypeID.IsForeignKey = false;
				colvarTypeID.IsReadOnly = false;
				colvarTypeID.DefaultSetting = @"";
				colvarTypeID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarTypeID);
				
				TableSchema.TableColumn colvarUID = new TableSchema.TableColumn(schema);
				colvarUID.ColumnName = "uID";
				colvarUID.DataType = DbType.Int32;
				colvarUID.MaxLength = 0;
				colvarUID.AutoIncrement = false;
				colvarUID.IsNullable = true;
				colvarUID.IsPrimaryKey = false;
				colvarUID.IsForeignKey = false;
				colvarUID.IsReadOnly = false;
				colvarUID.DefaultSetting = @"";
				colvarUID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarUID);
				
				TableSchema.TableColumn colvarRemark = new TableSchema.TableColumn(schema);
				colvarRemark.ColumnName = "Remark";
				colvarRemark.DataType = DbType.String;
				colvarRemark.MaxLength = 1073741823;
				colvarRemark.AutoIncrement = false;
				colvarRemark.IsNullable = true;
				colvarRemark.IsPrimaryKey = false;
				colvarRemark.IsForeignKey = false;
				colvarRemark.IsReadOnly = false;
				colvarRemark.DefaultSetting = @"";
				colvarRemark.ForeignKeyTableName = "";
				schema.Columns.Add(colvarRemark);
				
				TableSchema.TableColumn colvarTStatus = new TableSchema.TableColumn(schema);
				colvarTStatus.ColumnName = "tStatus";
				colvarTStatus.DataType = DbType.Int32;
				colvarTStatus.MaxLength = 0;
				colvarTStatus.AutoIncrement = false;
				colvarTStatus.IsNullable = true;
				colvarTStatus.IsPrimaryKey = false;
				colvarTStatus.IsForeignKey = false;
				colvarTStatus.IsReadOnly = false;
				colvarTStatus.DefaultSetting = @"";
				colvarTStatus.ForeignKeyTableName = "";
				schema.Columns.Add(colvarTStatus);
				
				TableSchema.TableColumn colvarStatus = new TableSchema.TableColumn(schema);
				colvarStatus.ColumnName = "Status";
				colvarStatus.DataType = DbType.Int32;
				colvarStatus.MaxLength = 0;
				colvarStatus.AutoIncrement = false;
				colvarStatus.IsNullable = true;
				colvarStatus.IsPrimaryKey = false;
				colvarStatus.IsForeignKey = false;
				colvarStatus.IsReadOnly = false;
				colvarStatus.DefaultSetting = @"";
				colvarStatus.ForeignKeyTableName = "";
				schema.Columns.Add(colvarStatus);
				
				TableSchema.TableColumn colvarInTime = new TableSchema.TableColumn(schema);
				colvarInTime.ColumnName = "inTime";
				colvarInTime.DataType = DbType.DateTime;
				colvarInTime.MaxLength = 0;
				colvarInTime.AutoIncrement = false;
				colvarInTime.IsNullable = true;
				colvarInTime.IsPrimaryKey = false;
				colvarInTime.IsForeignKey = false;
				colvarInTime.IsReadOnly = false;
				
						colvarInTime.DefaultSetting = @"(getdate())";
				colvarInTime.ForeignKeyTableName = "";
				schema.Columns.Add(colvarInTime);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["CXDB"].AddSchema("CX_Remark",schema);
			}
		}
		#endregion
		
		#region Props
		  
		[XmlAttribute("RID")]
		[Bindable(true)]
		public int RID 
		{
			get { return GetColumnValue<int>(Columns.RID); }
			set { SetColumnValue(Columns.RID, value); }
		}
		  
		[XmlAttribute("Guid")]
		[Bindable(true)]
		public Guid? Guid 
		{
			get { return GetColumnValue<Guid?>(Columns.Guid); }
			set { SetColumnValue(Columns.Guid, value); }
		}
		  
		[XmlAttribute("TypeID")]
		[Bindable(true)]
		public int? TypeID 
		{
			get { return GetColumnValue<int?>(Columns.TypeID); }
			set { SetColumnValue(Columns.TypeID, value); }
		}
		  
		[XmlAttribute("UID")]
		[Bindable(true)]
		public int? UID 
		{
			get { return GetColumnValue<int?>(Columns.UID); }
			set { SetColumnValue(Columns.UID, value); }
		}
		  
		[XmlAttribute("Remark")]
		[Bindable(true)]
		public string Remark 
		{
			get { return GetColumnValue<string>(Columns.Remark); }
			set { SetColumnValue(Columns.Remark, value); }
		}
		  
		[XmlAttribute("TStatus")]
		[Bindable(true)]
		public int? TStatus 
		{
			get { return GetColumnValue<int?>(Columns.TStatus); }
			set { SetColumnValue(Columns.TStatus, value); }
		}
		  
		[XmlAttribute("Status")]
		[Bindable(true)]
		public int? Status 
		{
			get { return GetColumnValue<int?>(Columns.Status); }
			set { SetColumnValue(Columns.Status, value); }
		}
		  
		[XmlAttribute("InTime")]
		[Bindable(true)]
		public DateTime? InTime 
		{
			get { return GetColumnValue<DateTime?>(Columns.InTime); }
			set { SetColumnValue(Columns.InTime, value); }
		}
		
		#endregion
		
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(Guid? varGuid,int? varTypeID,int? varUID,string varRemark,int? varTStatus,int? varStatus,DateTime? varInTime)
		{
			CxRemark item = new CxRemark();
			
			item.Guid = varGuid;
			
			item.TypeID = varTypeID;
			
			item.UID = varUID;
			
			item.Remark = varRemark;
			
			item.TStatus = varTStatus;
			
			item.Status = varStatus;
			
			item.InTime = varInTime;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varRID,Guid? varGuid,int? varTypeID,int? varUID,string varRemark,int? varTStatus,int? varStatus,DateTime? varInTime)
		{
			CxRemark item = new CxRemark();
			
				item.RID = varRID;
			
				item.Guid = varGuid;
			
				item.TypeID = varTypeID;
			
				item.UID = varUID;
			
				item.Remark = varRemark;
			
				item.TStatus = varTStatus;
			
				item.Status = varStatus;
			
				item.InTime = varInTime;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn RIDColumn
        {
            get { return Schema.Columns[0]; }
        }
        
        
        
        public static TableSchema.TableColumn GuidColumn
        {
            get { return Schema.Columns[1]; }
        }
        
        
        
        public static TableSchema.TableColumn TypeIDColumn
        {
            get { return Schema.Columns[2]; }
        }
        
        
        
        public static TableSchema.TableColumn UIDColumn
        {
            get { return Schema.Columns[3]; }
        }
        
        
        
        public static TableSchema.TableColumn RemarkColumn
        {
            get { return Schema.Columns[4]; }
        }
        
        
        
        public static TableSchema.TableColumn TStatusColumn
        {
            get { return Schema.Columns[5]; }
        }
        
        
        
        public static TableSchema.TableColumn StatusColumn
        {
            get { return Schema.Columns[6]; }
        }
        
        
        
        public static TableSchema.TableColumn InTimeColumn
        {
            get { return Schema.Columns[7]; }
        }
        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string RID = @"rID";
			 public static string Guid = @"Guid";
			 public static string TypeID = @"TypeID";
			 public static string UID = @"uID";
			 public static string Remark = @"Remark";
			 public static string TStatus = @"tStatus";
			 public static string Status = @"Status";
			 public static string InTime = @"inTime";
						
		}
		#endregion
		
		#region Update PK Collections
		
        #endregion
    
        #region Deep Save
		
        #endregion
	}
}
